﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace GA.Server.ApiInfo
{
    [Serializable]
    public class ApiHex
    {
        public int? AgencyId { get; private set; }
        public string AgencyName { get; private set; }
        public int? AllianceId { get; private set; }
        public string AllianceName { get; private set; }
        public string BuildingName { get; private set; }
        public bool IsHeadquarters { get; private set; }
        public int HexTerritoryId { get; private set; }
        public int HexZoneId { get; private set; }
        public int? HqProgress { get; private set; }
        public float ColorBlue { get; private set; }
        public float ColorGreen { get; private set; }
        public float ColorRed { get; private set; }
        public int Position { get; private set; }
        public int? ShieldProgress { get; private set; }
        public string ZoneName { get; private set; }
        public string ZoneType { get; private set; }

        public ApiHex()
        {
        }

        public ApiHex(XmlReader reader)
        {
            while (!reader.EOF)
            {
                reader.Read();
                if (reader.NodeType == XmlNodeType.Element)
                {
                    string value = ApiXmlNode.GetValue(reader);
                    switch (reader.Name)
                    {
                        case "a:agency_id": AgencyId = value == null ? null : (int?)int.Parse(value); break;
                        case "a:agency_na": AgencyName = value; break;
                        case "a:alliance_id": AllianceId = value == null ? null : (int?)int.Parse(value); break;
                        case "a:alliance_name": AllianceName = value; break;
                        case "a:building_na": BuildingName = value; break;
                        case "a:headquarter_flag": IsHeadquarters = value.Equals("121"); break;
                        case "a:hex_territory_id": HexTerritoryId = int.Parse(value); break;
                        case "a:hex_zone_id": HexZoneId = int.Parse(value); break;
                        case "a:hq_progress": HqProgress = value == null ? null : (int?)int.Parse(value); break;
                        case "a:position": Position = int.Parse(value); break;
                        case "a:shield_progress": ShieldProgress = (value == null || value.Equals("0")) ? null : (int?)int.Parse(value); break;
                        case "a:zone_na": ZoneName = value; break;
                        case "a:zone_type": ZoneType = value; break;
                    }
                }
            }
        }
    }
}
